import configparser
import os


# 读取配置文件
def read_config():
    # 获取当前文件所在目录
    root_dir = os.path.dirname(os.path.dirname(__file__))
    # 组装config.ini路径，也可以直接写配置文件的具体路径，不用自动获取
    config_dir = os.path.join(root_dir, 'resources', 'config.ini')

    # 创建configparser对象
    cf = configparser.ConfigParser()
    # 读取config.ini
    cf.read(config_dir, encoding="utf-8")
    return cf


cf = read_config()
temperature = cf.getint('info', 'temperature')
ollama_host = cf.get('ollama', 'host')
ollama_port = cf.getint('ollama', 'port')
ollama_model = cf.get('ollama', 'model')


deepseek_api_key = cf.get('deepseek', 'api_key')
deepseek_model = cf.get('deepseek', 'model')


milvus_url = cf.get('milvus', 'url')
milvus_db_name = cf.get('milvus', 'db_name')
milvus_mysql_collection = cf.get('milvus', 'mysql_collection')
# 问题映射collection
milvus_question_pk_collection = cf.get('milvus', 'question_pk_collection')
milvus_tool_collection = cf.get('milvus', 'tool_collection')
milvus_limit = cf.getint('milvus', 'limit')


model_embedding = cf.get('model', 'embedding')


mysql_ip = cf.get('mysql', 'ip')
mysql_port = cf.getint('mysql', 'port')
mysql_user_name = cf.get('mysql', 'user_name')
mysql_password = cf.get('mysql', 'password')
mysql_db = cf.get('mysql', 'db')

root_dir = os.path.dirname(os.path.dirname(__file__))
company_knn = os.path.join(root_dir, cf.get('algorithm', 'company_knn'))
company_tfidf = os.path.join(root_dir, cf.get('algorithm', 'company_tfidf'))


company_json = os.path.join(root_dir, cf.get('map', 'company_json'))


cyber_link_uuid = cf.get('its', 'cyber_link_uuid')
its_api_base_url = cf.get('its', 'api_base_url')